package test39;

import java.io.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-05-10
 * Time: 14:12
 */
//https://www.nowcoder.com/questionTerminal/9ae56e5bdf4f480387df781671db5172
public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String str = null;
        while ((str = br.readLine()) != null) {
            String[] strs = str.split(" ");
            String str1 = strs[0];
            int s1 = str1.length();
            String str2 = strs[1];
            int s2 = str2.length();
            int[][] dp = new int[s1 + 1][s2 + 1];
            for (int i = 1; i <= s1; i++) {
                char a = str1.charAt(i - 1);
                for (int j = 1; j <= s2; j++) {
                    char b = str2.charAt(j - 1);
                    if (a == b) {
                        dp[i][j] = dp[i - 1][j - 1] + 1;
                    } else {
                        dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                    }
                }
            }
            bw.write(dp[s1][s2] + "\n");
        }
        bw.flush();
        bw.close();
        br.close();
    }
}
